home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Game / R / ROBOT WARRIORS 1.0.1.CPT / Robot Warriors / Example Robots / Chicken next >
Text File  |  1991-08-26  |  11KB  |  396 lines

  1. ; Robot Name:  Chicken
  2. ;
  3. ;   Trys to dodge in the corner or run away until there is only one other robot
  4. ;   left.  Then it turns into a seeker.  This robot uses the concept of behavior
  5. ;   routines that can be repeatably called to provide a specific strategy.  
  6. ;   Each behavior routine may then select a different behavior routine in
  7. ;   different situations.
  8. ;   An improvement would be to know about walls and try to keep from getting
  9. ;   cornered by dodging into the open to a far corner, even if it means moving
  10. ;   closer to a robot in order to squeeze by it.
  11.  
  12. CPU_SPEED 0
  13. ARMOR 0
  14. FIRE_RATE 2
  15. ENGINE_SIZE 0
  16. RADAR_RANGE 1
  17. CLOAKING 1
  18. FUEL_CAPACITY 2
  19.  
  20. allocate midX
  21. allocate midy
  22. allocate quadrant
  23. allocate currentBehaviorRoutine
  24. allocate cornerCheckRoutine
  25. allocate quadrantDirection
  26. allocate doneMovingToCorner
  27. allocate clockTicks
  28. allocate timeInterruptBehaviorRoutine
  29. allocate circleSearchAim
  30. allocate aimIncrement
  31. allocate usingRadar   ;Semaphore used to tell interrupt code that radar register is in use
  32. allocate mainLineRadar
  33. allocate cornerDodgeDirection
  34. allocate oldDamage
  35. allocate oldAim
  36.  
  37. define kSafetyDistance 20
  38. define false 0
  39. define true 1
  40. define kDodgeOutDistance 60
  41.  
  42.     XMAX/2 to midx
  43.     YMAX/2 to midy
  44.     false to usingRadar
  45.     0 to clockTicks to circleSearchAim
  46.     GeneralInterrupt to timeInterruptBehaviorRoutine
  47.     TimeInterruptRoutine to time_int_xfer
  48.     1 to time_int_mask
  49.     0 to oldDamage
  50.  
  51.     if num_robots = 1 then
  52.         Seeker to currentBehaviorRoutine
  53.     else
  54.         MoveTowardsCorner to currentBehaviorRoutine
  55.     end
  56.  
  57. ;This is the Master Control Program that simply calls the current behavior routine.
  58. again   
  59.         gosub currentBehaviorRoutine
  60.         goto again
  61.  
  62. NullRoutine
  63.     return
  64.  
  65. ;  Behaviour routine:   DodgeBackAndForth
  66. ;
  67. ;  This routine is utilized when a robot is finally in a corner and just wants
  68. ;  to dodge back and forth in and out of the corner.  the cornerDodgeDirection
  69. ;  is assumed to be initialized.  If the robot collides, then it will move back
  70. ;  into the corner.
  71.  
  72. DodgeBackAndForth
  73.     20 to speed
  74.     cornerDodgeDirection to direction
  75.     DodgingOut to currentBehaviorRoutine
  76. DodgingOut  ;Dodging in will be done by
  77.     if num_robots = 1 then Seeker to currentBehaviorRoutine
  78.     gosub LookAndShoot
  79.     if speed = 0 then
  80.         gosub MoveTowardsCorner
  81.     else
  82.         if quadrant <= 2 then     ;Check for right wall, else left wall
  83.             if XMAX - kDodgeOutDistance > x then
  84.                 cornerDodgeDirection + 180 to direction
  85.                 gosub MoveTowardsCorner
  86.             end
  87.         else
  88.             if x > kDodgeOutDistance then
  89.                 cornerDodgeDirection + 180 to direction
  90.                 gosub MoveTowardsCorner
  91.             end
  92.         end
  93.     end
  94.     return
  95.  
  96. ;  Behavior routine:  MoveTowardsCorner
  97. ;
  98. ; Initializes by beginning to move into the nearest corner, then switches to
  99. ; ContinueMovingToCorner as the behavior routine.
  100. ;  ContinueMovingToCorner
  101. ; tries to safely move to the corner while avoiding collisions yet shooting
  102. ; the closest robot.  When the corner is found, switches to the 
  103. ; DodgeBackAndForth Behavior routine.
  104.  
  105. MoveTowardsCorner
  106.     gosub FindQuadrant
  107. BeginMoveTowardsQuadrant
  108.     gosub InitMoveTowardsQuadrant
  109.     direction to quadrantDirection
  110.     20 to speed
  111.     ContinueMovingToCorner to currentBehaviorRoutine
  112.     false to doneMovingToCorner
  113.     17 to aimIncrement
  114. return
  115.  
  116.  
  117.    ;Find the closest quadrant.  
  118.    ;Starting with the upper right, quadrants are 1,2,3,4 clockwise
  119.    
  120. FindQuadrant
  121.     if x < midx then
  122.         if y < midy then
  123.             4 to quadrant
  124.         else
  125.             3 to quadrant
  126.         end
  127.     else
  128.         if y < midy then
  129.             1 to quadrant
  130.         else
  131.             2 to quadrant
  132.         end
  133.     end
  134. return
  135.  
  136.  
  137.  
  138. InitMoveTowardsQuadrant
  139.     if quadrant = 1 then
  140.         XMAX-x to X_Conv
  141.         0-y to Y_Conv
  142.         Angle_Conv to direction
  143.         quad1 to cornerCheckRoutine
  144.     else
  145.         if quadrant = 2 then
  146.             XMAX-x to X_Conv
  147.             YMAX-y to Y_Conv
  148.             Angle_Conv to direction
  149.             quad2 to cornerCheckRoutine
  150.         else
  151.             if quadrant = 3 then
  152.                 0-x to X_Conv
  153.                 YMAX-y to Y_Conv
  154.                 Angle_Conv to direction
  155.                 quad3 to cornerCheckRoutine
  156.             else
  157.                 0-x to X_Conv
  158.                 0-y to Y_Conv
  159.                 Angle_Conv to direction
  160.                 quad4 to cornerCheckRoutine
  161.             end
  162.         end
  163.     end
  164. return
  165.  
  166.  
  167.  
  168.  
  169. ;  Behavior routine:  ContinueMovingToCorner
  170. ;
  171. ;  ContinueMovingToCorner tries to safely move to the assigned corner while avoiding
  172. ;  collisions, yet shooting at the closest robot.  When the corner is found, 
  173. ;  switches to the DodgeBackAndForth Behavior routine.
  174.  
  175. ContinueMovingToCorner
  176.     if num_robots = 1 then Seeker to currentBehaviorRoutine
  177.     if speed = 0 then 
  178.         -20 to speed
  179.         true to doneMovingToCorner
  180.     else
  181.         gosub cornerCheckRoutine
  182.     end
  183.     if doneMovingToCorner = true then
  184.         DodgeBackAndForth to currentBehaviorRoutine
  185.     else
  186.         gosub LookAndShoot
  187.     end
  188. return
  189.  
  190. ;   Corner Check Routines;
  191. ;
  192. ; In the quadrant corner detectors, stop the robot only when both X and Y
  193. ; directions are close to the wall.
  194.  
  195. quad1
  196.     if XMAX-kSafetyDistance < x then
  197.         0 to direction
  198.         if y < kSafetyDistance then
  199.             0 to speed
  200.             TRUE to doneMovingToCorner
  201.             215 to cornerDodgeDirection
  202.         end
  203.     else
  204.         if y < kSafetyDistance then 90 to direction
  205.     end
  206. return
  207.  
  208. quad2
  209.     if XMAX-kSafetyDistance < x then
  210.         180 to direction
  211.         if YMAX-kSafetyDistance < y then 
  212.             0 to speed
  213.             TRUE to doneMovingToCorner
  214.             305 to cornerDodgeDirection
  215.         end
  216.     else
  217.         if YMAX-kSafetyDistance < y then 90 to direction
  218.     end
  219. return
  220.  
  221. quad3
  222.     if x < kSafetyDistance then
  223.         180 to direction
  224.         if YMAX-kSafetyDistance < y then
  225.             0 to speed
  226.             TRUE to doneMovingToCorner
  227.             45 to cornerDodgeDirection
  228.         end
  229.     else
  230.         if YMAX-kSafetyDistance < y then 270 to direction
  231.     end
  232. return
  233.  
  234. quad4
  235.     if x < kSafetyDistance then
  236.         0 to direction
  237.         if y < kSafetyDistance then
  238.             0 to speed
  239.             TRUE to doneMovingToCorner
  240.             135 to cornerDodgeDirection
  241.         end
  242.     else
  243.         if y < kSafetyDistance then 270 to direction
  244.     end
  245. return
  246.  
  247.  
  248.  
  249. LookAndShoot
  250.     true to usingRadar  ;lock out interrupt routine
  251.     aim + aimIncrement to aim to radar
  252.     radar to mainLineRadar      ;Save value so interrupt routine can use radar
  253.     false to usingRadar
  254.     if mainLineRadar > 0 then
  255.         if mainLineRadar < 100 then gosub CloakMe
  256.         if shot = 0 then 
  257.             mainLineRadar to shot
  258.         else
  259.             aim - aimIncrement - 1 to aim
  260.         end
  261.         1 to aimIncrement
  262.     else
  263.         aimIncrement + 1 to aimIncrement
  264.         if aimIncrement > 17 then 17 to aimIncrement
  265.     end
  266. return
  267.  
  268.  
  269. ; Look ahead for collision and check for damage.  This is a time interrupt behavior routine ment to
  270. ; be called during interrupt time.
  271. GeneralInterrupt
  272.     if damage <> oldDamage then
  273.         gosub CloakMe
  274.         damage to oldDamage
  275.     end
  276.     if usingRadar <> true then  ;Use semaphore so we don't mess up mainline variables.
  277.         direction to radar
  278.         if radar > 0 then
  279.             if radar < 100 then
  280.                 if shot = 0 then radar to shot
  281.                 quadrant mod 4 + 1 to quadrant
  282.                 gosub BeginMoveTowardsQuadrant
  283.             end
  284.         end
  285.     end
  286. return
  287.  
  288.  
  289.  
  290. ;  Behavior routine:  Seeker
  291. ;
  292. ;  Seeks out and chases down enemy robot while trying not to collide with it.
  293. Seeker
  294.     NullRoutine to timeInterruptBehaviorRoutine
  295.     ContinueSeeker to currentBehaviorRoutine
  296.  
  297.     ;Start off towards the center of the arena
  298.     if x < 180 then
  299.       if y < 150 then
  300.         135 to direction  ;in upper left, move towards lower right
  301.       else
  302.         45 to direction   ;in lower left, move towards upper right
  303.       end
  304.     else
  305.       if y < 150 then
  306.         225 to direction  ;in upper right, move towards lower left
  307.       else
  308.         315 to direction  ;in lower right, moved towards upper left
  309.       end
  310.     end
  311.     20 to speed
  312.  
  313. ContinueSeeker
  314.     repeat
  315.       if speed = 0 then
  316.         gosub CloakMe
  317.         120 + direction to direction  ;Move away from possible collision source
  318.         20 to speed
  319.       end
  320.       if X < 20 then 90 to direction
  321.       if Y < 20 then 180 to direction
  322.       if X > 360 then 270 to direction
  323.       if Y > 290 then 0 to direction
  324.       if damage <> oldDamage then gosub CloakMe
  325.       aim + 3 to aim
  326.       true to usingRadar  ;lock out interrupt routine
  327.       aim to radar 
  328.       radar to mainLineRadar
  329.       false to usingRadar
  330.     until mainLineRadar > 0
  331.  
  332.     aim to direction
  333.     if mainLineRadar < 80 then gosub CloakMe
  334.     
  335.     ;Try to avoid hitting the other robot
  336.     
  337.     if mainLineRadar < 110 then aim - 10 to direction
  338.     if mainLineRadar < 85 then aim - 30 to direction
  339.     if mainLineRadar < 45 then 
  340.           aim - 120 to direction
  341.     else
  342.       if mainLineRadar < 85 then aim - 40 to direction
  343.     end
  344.  
  345.     if shot > 0 then
  346.       aim - 9 to aim
  347.     else
  348.       aim to oldAim
  349.       300/mainLineRadar + aim - 1 to aim  ;Try to hit the center of the enemy robot
  350.       
  351.       ;Usually enemy robots are moving away, shoot ahead of them.
  352.       mainLineRadar / 10 + mainLineRadar to shot
  353.             
  354.       oldAim to aim
  355.       aim - 4 to aim
  356.     end
  357. return
  358.  
  359.  
  360. ;Try to hide while conserving fuel
  361.  
  362. CloakMe
  363.     damage to oldDamage
  364.     if damage > 75 then  ;about to die
  365.         fuel/50 to cloak
  366.         if damage > 90 then cloak + 10 to cloak  ;really about to die
  367.     else
  368.         if fuel < 150 then  ;almost out of fuel don't cloak to much
  369.             2 to cloak       ;Only cloak enough to possibly trick other robot.  
  370.             if damage > 95 then 5 to cloak  ;Also about to die, oh no!
  371.         else
  372.             if fuel > 1500 then   ;Lots of fuel, clock for awhile
  373.                 12 to cloak
  374.             else
  375.                 if fuel > 750 then   ;Not as much fuel, don't cloak as long
  376.                     10 to cloak
  377.                 else
  378.                      5 to cloak     ;Not much fuel
  379.                 end
  380.             end
  381.         end
  382.     end
  383. return
  384.  
  385.  
  386.  
  387.  
  388.  
  389. ; Time interrupt routine simply keeps a clock count and calls the
  390. ; current interrupt Behavior routine.
  391.  
  392. TimeInterruptRoutine
  393.     clockTicks + 1 to clockTicks
  394.     if cloak > 0 then cloak - 1 to cloak
  395.     gosub timeInterruptBehaviorRoutine
  396. endint